package com.bvbot.core.bot;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;

public class UniqueTransactionIdGenerator {

	private final Date startDate = new Date();

	private String applicationSessionId = null;

	private static final DateFormat formatter = new SimpleDateFormat(
			"yyyyMMddHHmmss");

	private final AtomicInteger incrementor = new AtomicInteger();

	public Date getStartDate() {
		return startDate;
	}

	private String getApplicationSessionId() {
		if (applicationSessionId == null) {
			applicationSessionId = formatter.format(getStartDate());
		}
		return applicationSessionId;
	}

	public String getNewUniqueTransactionId() {
		String result = getApplicationSessionId() + "_"
				+ incrementor.getAndAdd(1);
		return result;
	}

}
